/*************************************************************************
 *
 *  Copyright (C) SEIKO EPSON CORP. 1997
 *  All Rights Reserved
 *
 *  Filename : ros33.h
 *  Function : for C33 itron
 *  Revision :
 *          1997/08/01  H.Matsuoka  start
 *          1999/08/26  H.Matsuoka  Add message buffer function
 *          1999/10/18  H.Matsuoka  Add semapho count change function
 *          1999/11/25  H.Matsuoka  Add system call from interrupt handler
 *          2000/02/28  H.Matsuoka  Ver2.0
 *          2000/11/21  Y.Taka      Add Memory Pool Management
 *          2001/01/16  Y.Taka      Add tslp_tsk,twai_sem,twai_flg,trcv_msg
 *          2003/03/27  A.Saito     Modify definition wai_flg, pol_flg
 *                                  Remove definition GLOBAL_POINTER
 *                                  Add definition 
 *
 ************************************************************************/

#ifndef _ROS33INC_
#define _ROS33INC_

#include "itron.h"

#define slp_tsk()  tslp_tsk(TMO_FEVR)

#define wai_sem(semid)  twai_sem(semid, TMO_FEVR)
#define preq_sem(semid) twai_sem(semid, TMO_POL)

#define wai_flg(p_flgptn,flgid,waiptn,wfmode) twai_flg(p_flgptn,flgid,waiptn,wfmode,TMO_FEVR)
#define pol_flg(p_flgptn, flgid, waiptn, wfmode) twai_flg(p_flgptn,flgid,waiptn,wfmode,TMO_POL)
#define snd_mbf(mbfid, msg, msgsz) tsnd_mbf(mbfid, msg, msgsz, TMO_FEVR)
#define psnd_mbf(mbfid, msg, msgsz) tsnd_mbf(mbfid, msg, msgsz, TMO_POL)
#define rcv_mbf(mbfid, msg, msgsz) trcv_mbf(mbfid, msg, msgsz, TMO_FEVR)
#define prcv_mbf(mbfid, msg, msgsz) trcv_mbf(mbfid, msg, msgsz, TMO_POL)
#define rcv_msg(ppk_msg, mbxid)     trcv_msg(ppk_msg, mbxid, TMO_FEVR)
#define prcv_msg(ppk_msg, mbxid)    trcv_msg(ppk_msg, mbxid, TMO_POL)
#define get_blk(p_blk, mplid, blksz)  tget_blk(p_blk, mplid, blksz, TMO_FEVR)
#define pget_blk(p_blk, mplid, blksz) tget_blk(p_blk, mplid, blksz, TMO_POL)
#define get_blf(p_blf, mpfid)         tget_blf(p_blf, mpfid, TMO_FEVR)
#define pget_blf(p_blf, mpfid)        tget_blf(p_blf, mpfid, TMO_POL)


// system call from interrupt handler 
extern ER   iwup_tsk( ID tskid );
extern ER   isig_sem( ID semid );
extern ER   iset_flg( ID flgid, UINT setptn );
extern ER   isnd_msg( ID mbxid, T_MSG *pk_msg );
extern ER   ipsnd_mbf( ID mbfid, VP msg, INT msgsz );
extern ER   ipget_blk( VP *p_blk, ID mplid, INT blksz );
extern ER   ipget_blf( VP *p_blf, ID mpfid );
extern ER   irel_blk( ID mplid, VP blk );
extern ER   irel_blf( ID mpfid, VP blf );


extern ER vcre_tsk( ID tskid, FP task, PRI tskpri, UW istkadr );
extern ER vcre_mbf( ID mbfid, VP  msgbuf, INT bufsz, INT maxmsz );
extern ER vcre_mpl( ID mplid, VP start_addr, VP end_addr );
extern ER vcre_mpf( ID mpfid, VP start_addr, VP end_addr, INT blfsz );
extern ER vchg_semcnt(ID semid, UB semcnt);
extern int vchk_timer();

extern void sys_clk();
extern void sys_sta();
extern void sys_ini();

// If you change resource number please edit following.
#define SMPH_NUM    8               // max semaphore, 0 to 255
#define FLG_NUM     8               // max flag, 0 to 255
#define MLBX_NUM    8               // max mailbox, 0 to 255 
#define MSGBUF_NUM  8               // max masage buffer, 0 to 255 
#define MPLBLK_NUM  8               // max variable-memory pool block, 0 to 255 
#define MPFBLK_NUM  8               // max fixed-memory pool block, 0 to 255 
#define TSK_NUM     8               // max task, 1 to 255 

#define CYCHNDR_NUM  8              // max cyclic handler, 0 to 255 
#define ALMHNDR_NUM  8              // max alarm handler, 0 to 255 

#define MAX_TSKPRI  8               // max task priority, 1 to 9

#define SMPH_CNT    1               // semaphore count, 1 to 255
#define WUP_CNT     1               // max wakeup count 1 to 65535

#define INI_PSR     0x00000010      // initial flag (%PSR value)
                                    // default is interrupt enable 
#define INT_TIME    1               // timer interrupt time (msec)
                                    
#endif // _ROS33INC_
